<template>
  <div class="container">
    <div class="submit-order">
      <!-- 收货地址 -->
      <div class="delivery-addr" @click="toAddrListPage">
        <div class="addr-bg" v-if="!userAddr">
          <div class="add-addr">
            <div class="plus-sign-img">
              <image src="../../static/images/icon/plus-sign.png"></image>
            </div>
            <text>新增收货地址</text>
          </div>
          <div class="arrow empty"></div>
        </div>
        <div class="addr-bg whole" v-if="userAddr">
          <div class="addr-icon">
            <image src="../../static/images/icon/addr.png"></image>
          </div>
          <div class="user-info">
            <text class="item">{{ userAddr.receiver }}</text>
            <text class="item">{{ userAddr.mobile }}</text>
          </div>
          <div class="addr">
            {{ userAddr.province }}{{ userAddr.city }}{{ userAddr.area
            }}{{ userAddr.addr }}
          </div>
          <div class="arrow"></div>
        </div>
      </div>

      <!-- 商品详情 -->
      <div class="prod-item">
        <block v-for="(item, index) in submintList" :key="index">
          <div class="item-cont">
            <div class="prod-pic">
              <img :src="item.pic" />
            </div>
            <div class="prod-info">
              <div class="prodname">
                {{ item.prodName }}
              </div>
              <div class="prod-info-cont">{{ item.skuName }}</div>
              <div class="price-nums">
                <text class="prodprice"
                  ><text class="symbol">￥</text>
                  <text class="big-num">{{ item.productTotalAmount }}</text>
                  <text class="small-num">.00</text></text
                >
                <text class="prodcount">x{{ item.prodCount }}</text>
              </div>
            </div>
          </div>
        </block>

        <div class="total-num">
          <text class="prodcount">共{{ submintList.length }}件商品</text>
          <div class="prodprice">
            合计：
            <text class="symbol">￥</text>
            <text class="big-num">{{ actualTotal }}</text>
            <text class="small-num"></text>
          </div>
        </div>
      </div>

      <!-- 订单详情 -->
      <div class="order-msg">
        <div class="msg-item">
          <div class="item coupon">
            <text class="item-tit">优惠券：</text>
            <text class="item-txt" v-if="!coupons.canUseCoupons">暂无可用</text>
            <text class="coupon-btn"
              >{{ coupons.totalLength ? coupons.totalLength : 0 }}张</text
            >
            <text class="arrow"></text>
          </div>
          <div class="item">
            <text>买家留言：</text>
            <input :value="remarks" placeholder="给卖家留言" />
          </div>
        </div>
      </div>

      <div class="order-msg">
        <div class="msg-item">
          <div class="item">
            <div class="item-tit">订单总额：</div>
            <div class="item-txt price">
              <text class="symbol">￥</text>
              <text class="big-num">{{ actualTotal }}</text>
              <text class="small-num"></text>
            </div>
          </div>
          <div class="item">
            <div class="item-tit">运费：</div>
            <div class="item-txt price">
              <text class="symbol">￥</text>
              <text class="big-num">0</text>
              <text class="small-num"></text>
            </div>
          </div>
          <div class="item">
            <div class="item-tit">优惠金额：</div>
            <div class="item-txt price">
              <text class="symbol">-￥</text>
              <text class="big-num">0</text>
              <text class="small-num"></text>
            </div>
          </div>
          <div class="item payment">
            <div class="item-txt price">
              小计：
              <text class="symbol">￥</text>
              <text class="big-num">{{ actualTotal }}</text>
              <text class="small-num"></text>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部栏 -->
    <div class="submit-order-footer">
      <div class="sub-order">
        <div class="item-txt">
          合计：
          <div class="price">
            <text class="symbol">￥</text>
            <text class="big-num">{{ actualTotal }}</text>
            <text class="small-num"></text>
          </div>
        </div>
      </div>
      <div class="footer-box" @click="showPopup">提交订单</div>
    </div>
    <van-popup
      :show="show"
      closeable
      position="bottom"
      custom-style="height: 50%"
      @close="onClose"
    >
      <div @click="goDetail">5555</div>
    </van-popup>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      show: false,
      orderEntry: "",
    };
  },
  computed: {
    // 获取vuex 状态
    ...mapState("submitOrder", [
      "userAddr",
      "subData",
      "detailOrder",
      "submintList",
      "actualTotal",
      "orderNumbers",
    ]),

    ...mapState("basket", ["basketList"]),
  }, 
  // 这里去掉了mounted 使用onLoad实现了商品详情和订单结算的购买的兼容
  onLoad(options) {
    this.getSubmitOrderInfo(options);
  },
  methods: {
    ...mapActions("submitOrder", [
      "getSubmitOrderInfo",
      "postSubmit",
      "postpay",
    ]),
    toAddrListPage() {
      if (this.orderEntry === "1") {
        wx.navigateTo({
          url: "/pages/delivery-address/index?order=1",
        });
      } else {
        wx.navigateTo({
          url: "/pages/delivery-address/index?order=0",
        });
      }
    },
    showPopup() {
      let orderShopParam = { orderShopParam: [{ remarks: "", shopId: 1 }] };
      this.postSubmit(orderShopParam).then((res) => {
        if (this.$store.state.submitOrder.orderNumbers) {
        console.log(this.$store.state.submitOrder.orderNumbers, 11111);
        this.postpay({
          payType: 1,
          orderNumbers: this.$store.state.submitOrder.orderNumbers,
        });
      }
      });
     
    },
    onClose() {
      this.show = false;
    },
    goDetail() {
      wx.navigateTo({
        url: "/pages/pay-result/index",
      });
    },
  },
};
</script>

<style scoped>
/* 收货地址 */

.submit-order {
  margin-bottom: 100rpx;
}

.submit-order .delivery-addr {
  position: relative;
  background: #fff;
}

.delivery-addr .addr-bg .add-addr .plus-sign {
  color: #eb2444;
  border: 2rpx solid #eb2444;
  padding: 0rpx 6rpx;
  margin-right: 10rpx;
}

.delivery-addr .addr-bg {
  padding: 0 30rpx;
}

.delivery-addr .addr-bg.whole {
  padding: 0 39rpx 0 77rpx;
}

.delivery-addr .addr-bg .add-addr {
  font-size: 28rpx;
  color: #666;
  display: flex;
  align-items: center;
  padding: 30rpx 0;
}

.submit-order .delivery-addr .addr-icon {
  width: 32rpx;
  height: 32rpx;
  display: block;
  position: absolute;
  left: 30rpx;
  top: 24rpx;
}

.submit-order .delivery-addr .addr-icon image {
  width: 100%;
  height: 100%;
}

.submit-order .delivery-addr .user-info {
  padding-top: 20rpx;
  line-height: 48rpx;
  word-wrap: break-word;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.submit-order .delivery-addr .user-info .item {
  font-size: 30rpx;
  margin-right: 30rpx;
  vertical-align: top;
  display: inline-block;
}

.submit-order .delivery-addr .addr {
  font-size: 26rpx;
  line-height: 36rpx;
  color: #999;
  width: 90%;
  padding-bottom: 20rpx;
  margin-top: 15rpx;
}

.submit-order .delivery-addr .arrow {
  width: 15rpx;
  height: 15rpx;
  border-top: 2rpx solid #777;
  border-right: 2rpx solid #777;
  transform: rotate(45deg);
  position: absolute;
  right: 30rpx;
  top: 60rpx;
}

.submit-order .delivery-addr .arrow.empty {
  top: 39rpx;
}

.addr-bg .add-addr .plus-sign-img {
  width: 32rpx;
  height: 32rpx;
  font-size: 0;
  margin-right: 10rpx;
}

.addr-bg .add-addr .plus-sign-img image {
  width: 100%;
  height: 100%;
}

/* 商品列表 */

.prod-item {
  background-color: #fff;
  margin-top: 15rpx;
  font-size: 28rpx;
}

.prod-item .item-cont .prod-pic image {
  width: 180rpx;
  height: 180rpx;
}

.prod-item .order-num {
  padding: 20rpx 30rpx;
  display: flex;
  justify-content: space-between;
  font-size: 28rpx;
}

.order-state {
  display: flex;
  align-items: center;
}

.prod-item .item-cont {
  display: flex;
  align-items: center;
  padding: 30rpx;
  border-bottom: 2rpx solid #f1f1f1;
}

.prod-item .order-num .clear-btn {
  width: 32rpx;
  height: 32rpx;
  font-size: 0;
  vertical-align: top;
  margin-top: 6rpx;
  margin-left: 42rpx;
  position: relative;
}

.prod-item .order-num .clear-btn::after {
  content: " ";
  display: block;
  position: absolute;
  left: -10px;
  top: 1px;
  width: 1px;
  height: 12px;
  background: #ddd;
}

.prod-item .order-num .clear-btn .clear-list-btn {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

.prod-item .item-cont .prod-pic {
  font-size: 0;
  display: block;
  width: 160rpx;
  height: 160rpx;
  overflow: hidden;
  background: #fff;
  margin-right: 16rpx;
}

.prod-item .item-cont .prod-pic image {
  width: 100%;
  height: 100%;
}

.prod-item .item-cont .prod-info {
  margin-left: 10rpx;
  font-size: 28rpx;
  width: 100%;
  position: relative;
  height: 160rpx;
  -webkit-flex: 1;
  -ms-flex: 1;
  -webkit-box-flex: 1;
  -moz-box-flex: 1;
  flex: 1;
}

.prod-item .item-cont .prod-info .prodname {
  font-size: 28rpx;
  line-height: 40rpx;
  max-height: 86rpx;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  word-break: break-all;
}

.prod-item .item-cont .prod-info .prod-info-cont {
  color: #999;
  line-height: 40rpx;
  margin-top: 10rpx;
  font-size: 22rpx;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  word-break: break-all;
}

.prod-item .total-num {
  text-align: right;
  padding: 20rpx 30rpx;
  font-size: 28rpx;
}

.prod-item .price-nums .prodprice {
  position: absolute;
  bottom: 0;
}

.prod-item .price-nums .prodcount {
  position: absolute;
  bottom: 5rpx;
  right: 0;
  color: #999;
  font-family: verdana;
}

.prod-item .total-num .prodprice {
  display: inline-block;
  color: #333;
}

.prod-item .total-num .prodcount {
  margin-right: 20rpx;
}

/* 
订单信息 */

.order-msg {
  background: #fff;
  margin-top: 15rpx;
  padding: 0 30rpx;
  font-size: 28rpx;
}

.order-msg .msg-item {
  border-top: 2rpx solid #f1f1f1;
}

.order-msg .msg-item:first-child {
  border: 0;
}

.order-msg .msg-item .item {
  position: relative;
  display: flex;
  padding: 16rpx 0;
  align-items: center;
}

.order-msg .msg-item .item.payment {
  border-top: 2rpx solid #f1f1f1;
  color: #eb2444;
}

.order-msg .msg-item .item .item-tit {
  line-height: 48rpx;
}

.order-msg .msg-item .item .item-txt {
  -webkit-box-flex: 1;
  -moz-box-flex: 1;
  flex: 1;
  font-family: arial;
  max-height: 48rpx;
  overflow: hidden;
  line-height: 48rpx;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  word-break: break-all;
}

.price {
  color: #eb2444;
}

.big-num {
  font-size: 30rpx;
}
.small-num {
  font-size: 24rpx;
}

.order-msg .msg-item .item.coupon {
  border-bottom: 2rpx solid #e1e1e1;
}

.order-msg .msg-item .item input {
  flex: 1;
}

.order-msg .msg-item .item .coupon-btn {
  display: block;
  margin: 0 30rpx;
  line-height: 28rpx;
  color: #999;
}

.order-msg .msg-item .item .item-txt.price {
  text-align: right;
}

.order-msg .msg-item .item .arrow {
  width: 15rpx;
  height: 15rpx;
  border-top: 2rpx solid #999;
  border-right: 2rpx solid #999;
  transform: rotate(45deg);
  position: absolute;
  right: 0rpx;
}

/* 底部栏 */

.submit-order-footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  max-width: 750rpx;
  background: #fff;
  margin: auto;
  display: -webkit-flex;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  font-size: 26rpx;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

.submit-order-footer .sub-order {
  flex: 1;
  margin: 0 30rpx;
  line-height: 100rpx;
  display: block;
  text-align: left;
  font-size: 28rpx;
}

.submit-order-footer .footer-box {
  padding: 0 10rpx;
  width: 200rpx;
  background: #eb2444;
  text-align: center;
  line-height: 100rpx;
  color: #fff;
}

.submit-order-footer .sub-order .item-txt .price {
  display: inline;
  color: #eb2444;
  font-size: 28rpx;
}

.clearfix:after {
  content: " ";
  display: table;
  clear: both;
}
</style>
